package dao

import "morleyStoneHome/model"

type pledgeDao struct {
}

var PledgeDao = newPledgeDao()

func newPledgeDao() *pledgeDao {
	return &pledgeDao{}
}

//查询最早的一条
func (n *pledgeDao) FindOne(addr string) (pledge []*model.Pledge, err error) {
	res := Db.Where("account = ? and tx_state = 100 ", addr).Order("ledger_index ASC").Limit(1).Find(&pledge)
	if res.Error != nil {
		return nil, res.Error
	}
	return pledge, nil
}

//列出表中所有成功质押的
func (n *pledgeDao) FindAll() (pledge []*model.Pledge, err error) {
	res := Db.Where("tx_state = 100 ").Find(&pledge)
	if res.Error != nil {
		return nil, res.Error
	}
	return pledge, nil
}
